package cn.stylefeng.guns.modular.filerun.controller;

import cn.stylefeng.guns.config.OssConfig;
import cn.stylefeng.guns.modular.filerun.model.FileUploadResult;
import cn.stylefeng.guns.modular.filerun.service.FileImgService;
import cn.stylefeng.guns.sys.core.util.UeditorUtil;
import cn.stylefeng.guns.sys.modular.system.model.UeditorFileResult;
import com.aliyun.oss.OSS;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/fileRun")
@Slf4j
public class FileRunUeditorController {

    // 允许上传的格式
    private static final String[] IMAGE_TYPE = new String[]{".bmp", ".jpg",
            ".jpeg", ".gif", ".png"};

    @Autowired
    private FileImgService fileImgService;
    /**
     * 图片上传
     *
     * @author fengshuonan
     * @Date 2019/8/26 15:19
     */
    @RequestMapping(value = "/imgUpdate")
    @ResponseBody
    public UeditorFileResult imgUpdate(@RequestParam(value = "upfile") MultipartFile upfile) {
        FileUploadResult fileUploadResult = fileImgService.uploadFileByOss(upfile);
        UeditorFileResult ueditorFileResult= new UeditorFileResult();
        ueditorFileResult.setUrl(fileUploadResult.getName());
        return ueditorFileResult;
    }
}
